<?php

namespace App\Http\Middleware;

use Closure;

class WeChatSession
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $redis = app('redis.connection');
        $loginInfoJson = $redis->get('_3rd_session:' . request('session'));
        if ($loginInfoJson == NULL) {
            return response()->json(['status' => false, 'message' => 'Session error']);
        }
        $loginInfo = json_decode($loginInfoJson, JSON_FORCE_OBJECT);
        $request['loginInfo'] = $loginInfo;
        return $next($request);
    }
}
